package cc.ruih.meizanchen;

import cc.ruih.meizanchen.bb.BBIndex;
import cc.ruih.meizanchen.mm.MMIndex;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

/**
 * 程序进入首页
 * @author 郭瑞坡
 *
 */
public class Main extends Activity {

	Button ymm;		// 我是孕妈妈
	Button bmm;		// 我是宝宝妈妈
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ymm = (Button) findViewById(R.id.wsymm);
        bmm = (Button) findViewById(R.id.wsbmm);
        ymm.setOnClickListener(ButtonClick);
        bmm.setOnClickListener(ButtonClick);
    }
    
    @Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode==KeyEvent.KEYCODE_BACK){
			finish();		// 退出应用程序
		}
		return super.onKeyDown(keyCode, event);
	}
    
    private OnClickListener ButtonClick = new OnClickListener() {
		@Override
		public void onClick(View v) {
			Intent intent = new Intent();
			switch (v.getId()) {
			case R.id.wsymm:
				SharedPreferences sharedPreferences = getSharedPreferences("mminfo", Context.MODE_PRIVATE);
				String motherName = sharedPreferences.getString("name", "");
				if(motherName!=null&&motherName!=""&&motherName.length()>0){
					intent.setClass(Main.this, MMIndex.class);		// 跳转到妈妈首页
				}else{
					intent.setClass(Main.this, MMLogin.class);		// 跳转到妈妈档案页面
				}
				break;
			case R.id.wsbmm:
				SharedPreferences sharedPreferences2 = getSharedPreferences("bbinfo", Context.MODE_PRIVATE);
				String bbname = sharedPreferences2.getString("bbname", "");
				// 判断是否存储宝宝的信息
				if(bbname!=null&&bbname!=""&&bbname.length()>0){
					intent.setClass(Main.this, BBIndex.class);		// 跳转到宝宝首页
				}else{
					intent.setClass(Main.this, BBLogin.class);		// 跳转到宝宝档案页面
				}
				break;
			}
			startActivity(intent);
		}
    };
    
}
